<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/sql_rt" prefix="sql" %>

<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>SQL-JSTL DEMO</title>
	<link href="styles.css" rel="stylesheet"/>
</head>
<body>
<h1 style="text-align: center; color: blue">SQL-JSTL DEMO</h1>
<form action="SqlJstl.jsp" method="post">
	Filter Expression: 
	<input name="txtSearch" value="${param['txtSearch']}" size="40">
	<input type="submit" name="btnSearch" value="Search">
</form>
<div style="text-align: center;">
	<!-- câu lệnh truy vấn -->
	<sql:query var="result">
		SELECT * FROM Products 
		<c:if test="${!empty param['btnSearch']}">
			WHERE Name LIKE '%${param['txtSearch']}%'
		</c:if>
		ORDER BY NewID()
	</sql:query>
	
	<!-- hiển thị kết quả truy vấn -->
	<c:forEach var="pro" items="${result.rows}">
	<div class="pro-box">
		<div class="pro-name">${pro.Name}</div>
		<img class="pro-image" src="Hinh/HangHoa/${pro.Image}">
		<div class="pro-price">$${pro.UnitPrice}</div>
		<div class="pro-icons">
			<img src="Hinh/icons/Favourites.png">
			<img src="Hinh/icons/Letter.png">
			<img src="Hinh/icons/Add to basket.png">
		</div>
	</div>
	</c:forEach>	
</div>
</body>
</html>